<template>
  <div>
    <inputgoods></inputgoods>
    <!-- 所有商品列表 -->
    <!-- 第一层 -->
    <div class="main" v-for="item in allgoodslist" :key="item.cat_id">
      <p class="onetitle">{{ item.cat_name }}</p>
      <!-- 第二层 -->
      <div class="list" v-for="a in item.children" :key="a.cat_id">
        <p class="twotitle">{{ a.cat_name }}</p>
        <!-- 第三层 -->
        <div class="item" v-for="b in a.children" :key="b.cat_id">
            <p class="trtitle">{{ b.cat_name }}</p>
            <img @error="reload" :src="b.cat_icon" alt="" @click="gogoodslist(b.cat_id)">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Inputgoods from "./inputgoods.vue";
import navlist from "./navlist.vue";
import { categories } from "../request/goods/index";
export default {
  components: { navlist, Inputgoods },
  name: "VueAllgoods",

  data() {
    return {
      allgoodslist: [],
    };
  },

  mounted() {
    this.init();
  },

  methods: {
    init() {
      categories()
        .then((res) => {
          this.allgoodslist = res.message;
        })
        .catch((err) => {});
    },
    //跳转列表
    gogoodslist(id){
        this.$router.push({
            path:"/goodslist",
            query:{url:id}
        })
    },
    //处理图片
    reload() {
      event.target.src =
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201706%2F19%2F20170619001755_dtHZv.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1641354085&t=7e7fccd04090184415674d69dcf4a803";
    },
  },
};
</script>

<style  scoped>
.main .onetitle{
font-size: 40px;
font-weight: 700;
color: #f0f;
margin: 10px 0;
width: fit-content;
background-color: #0ff;
padding: 10px 200px 10px 5px;
}
.list{
  overflow: hidden;
  border: 1px solid #a9a9a9;
  margin-top: -1px;
  padding-bottom: 5px;
}
.list .twotitle{
    font-size: 25px;
    font-weight: 600;
    color: #0f0;
    margin-top: 10px;
    text-indent: 1em;
    width: 100%;
    margin-bottom: 10px;
}
.item{
    display: inline-block;
    margin-left: 30px;
    text-align: center;
    margin-top: 10px;
    box-sizing: border-box;
}
.item img{
width: 100px;
height: 100px;
}
</style>